﻿using System;
using System.ComponentModel.Composition;

namespace SS.Common.Utilities
{
    [Export(typeof(CodeGenerationHelper))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class CodeGenerationHelper
    {
        private const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        private static readonly Random random = new Random((int)DateTime.Now.Ticks);

        public string GenerateRandomCode(int size)
        {
            var stringChars = new char[size];

            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }

            var result = new String(stringChars);
            return result;
        }
    }
}